package shared.Player;

import java.util.ArrayList;
import java.util.Random;

import shared.Tiles.Backwards2Tile;
import shared.Tiles.Backwards3Tile;
import shared.Tiles.Forward2Tile;
import shared.Tiles.Forward3Tile;
import shared.Tiles.QuestionTile;
import shared.Tiles.Tile;

public class Player {

	public int tileId;
	public int playerID;
	public String name;
	public int GameNo;
	public Tile current;
	public boolean rolled = false;
	public int rollRes = 0;
	public boolean anwsered = true;
	public boolean correctAnwser = true;
	public String[] question;
	public boolean dc = false;

	public Player(String name, int tileId, int playerID) {
		this.name = name;
		this.tileId = tileId;
		this.playerID = playerID;
	}

	public Player(String name, int tileId, int GameNo, int playerID, Tile entry) {
		this.name = name;
		this.tileId = tileId;
		this.GameNo = GameNo;
		this.playerID = playerID;
		current = entry;
	}

	public void rollDice() {
		Random rnd = new Random();
		rollRes = rnd.nextInt(4) + 1;
		rolled = true;
	}

	public void move(ArrayList<Tile> tiles) {
		if (correctAnwser) {
			if (current.tileId + rollRes <= 19) {
				current = tiles.get(current.tileId + rollRes);
			} else {
				current = tiles.get(19);
			}
		}
		if (current instanceof Backwards2Tile) {
			current = tiles.get(current.tileId - 2);
		}
		if (current instanceof Backwards3Tile) {
			current = tiles.get(current.tileId - 3);
		}
		if (current instanceof Forward2Tile) {
			current = tiles.get(current.tileId + 2);
		}
		if (current instanceof Forward3Tile) {
			current = tiles.get(current.tileId + 3);
		}
		if (current instanceof QuestionTile) {
			anwsered = false;
			correctAnwser = false;
		}
		rolled = false;
	}

}
